package com.example.demo.util.json;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

public class FileUtils {
    private static final String JSON_SUFFIX = ".json";
    private static final String BASE_PATH = "D:\\p\\";


    public static void writeJOSN(String jsonString, String fileName) {
        write(jsonString.getBytes(StandardCharsets.UTF_8), BASE_PATH + fileName + JSON_SUFFIX);
    }


    public static void write(byte[] b, String fileName) {
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(fileName);
            outputStream.write(b);
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (Objects.nonNull(outputStream)) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        File file = new File("D:\\p\\d");
        System.out.println(file.exists());
        System.out.println(file.isDirectory());
        boolean mkdirs = file.mkdirs();
        System.out.println(file.exists());
        System.out.println(file.isDirectory());


    }

}
